package top.liuziqian.web.controller.shop.goods;




import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.liuziqian.common.annotation.Log;
import top.liuziqian.common.core.controller.BaseController;
import top.liuziqian.common.core.domain.AjaxResult;
import top.liuziqian.common.core.page.TableDataInfo;
import top.liuziqian.common.enums.BusinessType;
import top.liuziqian.shop.domain.GoodsBrand;
import top.liuziqian.shop.service.IGoodsBrandService;
import top.liuziqian.system.domain.SysNotice;

import java.util.List;


@Controller
@RequestMapping("/goods/brand")
@Api("商品品牌管理")
public class BrandController extends BaseController {

    private String prefix = "shop/goods/brand";

    @Autowired
    private IGoodsBrandService brandService;

    @RequiresPermissions("goods:brand:view")

    @GetMapping()
    public String brand()
    {
        return prefix + "/brand";
    }


    /**
     * 新增品牌
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/edit/{brandId}")
    public String edit(@PathVariable("brandId") Long brandId, ModelMap mmap)
    {
        mmap.put("brand",brandService.selectBrandById(brandId));
        return prefix + "/edit";
    }

    /**
     * 查询品牌列表
     */
    @RequiresPermissions("goods:brand:list")
    @PostMapping("/list")
    @ResponseBody
    @ApiOperation("获取商品品牌")
    public TableDataInfo list(GoodsBrand brand)
    {
        startPage();
        List<GoodsBrand> list = brandService.selectBrandList(brand);
        return getDataTable(list);
    }


    /**
     * 新增品牌
     */
    @RequiresPermissions("goods:brand:add")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated GoodsBrand brand)
    {
        brand.setCreateBy(getLoginName());
        return toAjax(brandService.insertBrand(brand));
    }

    @RequiresPermissions("goods:brand:edit")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated GoodsBrand brand)
    {
        brand.setUpdateBy(getLoginName());
        return toAjax(brandService.updateBrand(brand));
    }

    /**
     * 删除品牌
     */
    @RequiresPermissions("goods:brand:remove")
    @Log(title = "品牌", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(brandService.deleteBrandByIds(ids));
    }
}

